home *** CD-ROM | disk | FTP | other *** search
- /***
- *
- * File: IAC.c
- *
- * Package: Inter Application Communications
- *
- * Description: This is the interface package to the driver for the use of
- * application programs.
- *
- * Author(s):
- * FEA 6/19/88
- *
- */
-
- # include <types.h>
- # include <files.h>
- # include <memory.h>
- # include <osutils.h>
- # include <serial.h>
- # include <iac.h>
-
- # define MIN_BLK_SIZE 0xC
- # define DEBUG false
-
- static short iac_ref_num;
-
- /**
- * Routine: iac_open
- *
- * The IAC driver is opened by this call and the ioRefNum saved so
- * it doesn't need to be passed with all calls. A null value is returned
- * if the open is successful; otherwise the operating system error is
- * returned.
- */
-
- short iac_open()
-
- {
- SysEnvRec theWorld; /* ALMOST complete knowledge about the world */
- THz s_ZoneP, a_ZoneP; /* so we can check zone adjacency */
- OSErr the_err;
-
- short result = 0;
-
- the_err = SysEnvirons(1, &theWorld);
- if (theWorld.systemVersion < 0x0420) /* too early! */
- {
- result = EARLY_SYS; /* "no multifinder" */
- }
- else
- {
- /* check for multifinder active by checking if system zone is
- adjacent to application zone, which never happens under
- MultiFinder.
- */
- s_ZoneP = SystemZone();
- a_ZoneP = ApplicZone();
- if ( ((long) s_ZoneP->bkLim + MIN_BLK_SIZE) == (long) a_ZoneP )
- {
- result = EARLY_SYS; /* zones adjacent - no multifinder */
- }
- else /* now try to actually open the IAC driver */
- {
- SysBeep(1);
- result = OPENDRIVER("\p.IAC", &iac_ref_num);
- }
- }
-
- return(result);
- }
-
-
- /**
- * Routine: iac_add_dependency
- *
- * This is used to inform the IAC driver that a new dependency has been
- * established and should be added to its internal tables. A null value is
- * returned if the open is successful; otherwise the operating system error
- * is returned.
- */
-
- short iac_add_dependency(doc_id, slot_id, hat_check, edition)
- long *doc_id; /* identifies the source document (permanent) */
- short *slot_id; /* identifies the source document (session) */
- short *hat_check; /* extent identifier */
- short *edition; /* how many times extent has changed (session) */
-
- {
- IOParam the_blk;
- OSErr the_err;
-
- struct {
- short func;
- long doc_id;
- short slot_id;
- short hat_check;
- short edition;
- } my_params;
-
- # if DEBUG
- return(the_err=noErr); /* short circuit for testing without MF */
- # endif
-
- my_params.func = 1; /* set up private parameter block */
- my_params.doc_id = *doc_id;
- my_params.slot_id = *slot_id;
- my_params.hat_check = *hat_check;
-
- the_blk.ioCompletion = nil; /* set up driver parameter block */
- the_blk.ioRefNum = iac_ref_num;
- the_blk.ioBuffer = &my_params;
- the_blk.ioReqCount = sizeof(my_params);
- the_blk.ioPosMode = fsFromStart;
- the_blk.ioPosOffset = 0;
- the_err = PBWrite(&the_blk.qLink, false); /* add the dependency */
-
- if (the_err == noErr) /* update output parameters */
- {
- *doc_id = my_params.doc_id;
- *slot_id = my_params.slot_id;
- *hat_check = my_params.hat_check;
- *edition = my_params.edition;
- }
-
- return(the_err);
- }
-
-
- /**
- * Routine: iac_complete_dependency
- *
- * This is used to inform the IAC driver of a document that is interested
- * in a particular dependency. A null value is returned if the open is
- * successful; otherwise the operating system error is returned.
- */
-
- short iac_complete_dependency(doc_id, slot_id, hat_check)
- long *doc_id; /* identifies the source document (permanent) */
- short *slot_id; /* identifies the source document (session) */
- short *hat_check; /* extent identifier */
-
- {
- IOParam the_blk;
- OSErr the_err;
-
- struct {
- short func;
- long doc_id;
- short slot_id;
- short hat_check;
- } my_params;
-
- # if DEBUG
- return(the_err=noErr); /* short circuit for testing without MF */
- # endif
-
- my_params.func = 2; /* set up private parameter block */
- my_params.doc_id = *doc_id;
- my_params.slot_id = *slot_id;
- my_params.hat_check = *hat_check;
-
- the_blk.ioCompletion = nil; /* set up driver parameter block */
- the_blk.ioRefNum = iac_ref_num;
- the_blk.ioBuffer = &my_params;
- the_blk.ioReqCount = sizeof(my_params);
- the_blk.ioPosMode = fsFromStart;
- the_blk.ioPosOffset = 0;
- the_err = PBWrite(&the_blk.qLink, false); /* complete the dependency */
-
- if (the_err == noErr) /* update output parameters */
- {
- *doc_id = my_params.doc_id;
- *slot_id = my_params.slot_id;
- *hat_check = my_params.hat_check;
- }
-
- return(the_err);
- }
-
-
- /**
- * Routine: iac_remove_dependency
- *
- * This is used to inform the IAC driver that a document is no longer
- * interested in a particular dependency. If the document is the original
- * source all "targets" will be informed that there is no longer any such
- * extent; if all targets lose interest the source will be informed that it
- * no longer needs to update the extent.
- */
-
- short iac_remove_dependency(doc_id, slot_id, hat_check)
- long doc_id; /* identifies the source document (permanent) */
- short slot_id; /* identifies the source document (session) */
- short hat_check; /* extent identifier */
-
- {
- IOParam the_blk;
- OSErr the_err;
-
- struct {
- short func;
- long doc_id;
- short slot_id;
- short hat_check;
- } my_params;
-
- # if DEBUG
- return(the_err=noErr); /* short circuit for testing without MF */
- # endif
-
- my_params.func = 3; /* set up private parameter block */
- my_params.doc_id = doc_id;
- my_params.slot_id = slot_id;
- my_params.hat_check = hat_check;
-
- the_blk.ioCompletion = nil; /* set up driver parameter block */
- the_blk.ioRefNum = iac_ref_num;
- the_blk.ioBuffer = &my_params;
- the_blk.ioReqCount = sizeof(my_params);
- the_blk.ioPosMode = fsFromStart;
- the_blk.ioPosOffset = 0;
- the_err = PBWrite(&the_blk.qLink, false); /* remove the dependency */
-
- return(the_err);
- }
-
-
- /**
- * Routine: iac_available_dependency
- *
- * This sets the indicated extent as the "available extent" to be used
- * as the source for future defaulted "complete_dependency" calls.
- */
-
- short iac_available_dependency(doc_id, hat_check)
- long doc_id; /* identifies the source document (permanent) */
- short hat_check; /* extent identifier */
-
- {
- IOParam the_blk;
- OSErr the_err;
-
- struct {
- short func;
- long doc_id;
- short hat_check;
- } my_params;
-
- # if DEBUG
- return(the_err=noErr); /* short circuit for testing without MF */
- # endif
-
- my_params.func = 4; /* set up private parameter block */
- my_params.doc_id = doc_id;
- my_params.hat_check = hat_check;
-
- the_blk.ioCompletion = nil; /* set up driver parameter block */
- the_blk.ioRefNum = iac_ref_num;
- the_blk.ioBuffer = &my_params;
- the_blk.ioReqCount = sizeof(my_params);
- the_blk.ioPosMode = fsFromStart;
- the_blk.ioPosOffset = 0;
- the_err = PBWrite(&the_blk.qLink, false); /* this dependency is now "available" */
-
- return(the_err);
- }
-
-
- /**
- * Routine: iac_status
- *
- * This allows the application program to find out what's going on.
- */
-
- short iac_status(slot_id, vers_id, doc_count, extent_count)
- short slot_id; /* identifies the inquiring document (session) */
- short *vers_id; /* driver version*100 */
- short *doc_count; /* count of active documents */
- short *extent_count; /* count of extents relevant to inquiring doc */
-
- {
- IOParam the_blk;
- OSErr the_err;
-
- struct {
- short func;
- short slot_id;
- short vers_id;
- short doc_count;
- short extent_count;
- } my_params;
-
- # if DEBUG
- return(the_err=noErr); /* short circuit for testing without MF */
- # endif
-
- my_params.func = 5; /* set up private parameter block */
- my_params.slot_id = slot_id;
-
- the_blk.ioCompletion = nil; /* set up driver parameter block */
- the_blk.ioRefNum = iac_ref_num;
- the_blk.ioBuffer = &my_params;
- the_blk.ioReqCount = sizeof(my_params);
- the_blk.ioPosMode = fsFromStart;
- the_blk.ioPosOffset = 0;
- the_err = PBRead(&the_blk.qLink, false); /* read IAC status */
-
- if (the_err == noErr) /* update output parameters */
- {
- *vers_id = my_params.vers_id;
- *doc_count = my_params.doc_count;
- *extent_count = my_params.extent_count;
- }
-
- return(the_err);
- }
-
-
- /**
- * Routine: iac_census
- *
- * This provides identifying info for all registered extents.
- */
-
- short iac_census(extent_count, extent_info)
- short *extent_count; /* count of extents registered */
- info_tblP extent_info; /* Ptr to table of info for each extent */
-
- {
- IOParam the_blk;
- OSErr the_err;
- short i;
-
- struct {
- short func;
- short extent_count;
- info_rec extent_info[MAX_EXTS];
- } my_params;
-
- # if DEBUG
- return(the_err=noErr); /* short circuit for testing without MF */
- # endif
-
- my_params.func = 6; /* set up private parameter block */
-
- the_blk.ioCompletion = nil; /* set up driver parameter block */
- the_blk.ioRefNum = iac_ref_num;
- the_blk.ioBuffer = &my_params;
- the_blk.ioReqCount = sizeof(my_params);
- the_blk.ioPosMode = fsFromStart;
- the_blk.ioPosOffset = 0;
- the_err = PBRead(&the_blk.qLink, false); /* read IAC status */
-
- if (the_err == noErr) /* update output parameters */
- {
- *extent_count = my_params.extent_count;
- BlockMove (&my_params.extent_info[0],
- (Ptr) extent_info,
- (long) my_params.extent_count * sizeof(info_rec));
- }
-
- return(the_err);
- }
-
-
- /**
- * Routine: iac_write_data
- *
- * This updates the data for the specified extent, resulting in a new
- * change level.
- */
-
- short iac_write_data(doc_id, hat_check, edition, fmt_count, ext_data)
- long doc_id; /* identifies the source document (permanent) */
- short hat_check; /* extent identifier */
- short *edition; /* how many times extent has changed (session) */
- short fmt_count; /* number of formats being written */
- Handle ext_data; /* Handle to actual data */
-
- {
- IOParam the_blk;
- OSErr the_err;
-
- struct {
- short func;
- long doc_id;
- short hat_check;
- short edition;
- short fmt_count;
- Handle the_dataH;
- } my_params;
-
- # if DEBUG
- return(the_err=noErr); /* short circuit for testing without MF */
- # endif
-
- my_params.func = 7; /* set up private parameter block */
- my_params.doc_id = doc_id;
- my_params.hat_check = hat_check;
- my_params.fmt_count = fmt_count;
- my_params.the_dataH = ext_data;
-
- the_blk.ioCompletion = nil; /* set up driver parameter block */
- the_blk.ioRefNum = iac_ref_num;
- the_blk.ioBuffer = &my_params;
- the_blk.ioReqCount = sizeof(my_params);;
- the_blk.ioPosMode = fsFromStart;
- the_blk.ioPosOffset = 0;
- the_err = PBWrite(&the_blk.qLink, false); /* update dependency */
-
- if (the_err == noErr) /* update output parameters */
- {
- *edition = my_params.edition;
- }
-
- return(the_err);
- }
-
-
- /**
- * Routine: iac_read_data
- *
- * This is used to retrieve the actual data for the latest change_level
- * for the specified extent. The IAC driver will record that the inquiring
- * document has read the data.
- *
- * ext_data will be resized by the driver to hold the data.
- */
-
- short iac_read_data(doc_id, slot_id, hat_check, edition, fmt_pref,
- fmt_code, ext_data)
- long doc_id; /* identifies the source document (permanent) */
- short slot_id; /* identifies the source document (session) */
- short hat_check; /* extent identifier */
- short *edition; /* how many times extent has changed (session) */
- long fmt_pref[3]; /* preferred formats, descending desirability */
- long *fmt_code; /* format returned to caller */
- Handle ext_data; /* Handle to actual data */
-
- {
- IOParam the_blk;
- OSErr the_err;
-
- struct {
- short func;
- long doc_id;
- short slot_id;
- short hat_check;
- short edition;
- long fmt_pref[3];
- long fmt_code;
- Handle ext_data;
- } my_params;
-
- # if DEBUG
- return(the_err=noErr); /* short circuit for testing without MF */
- # endif
-
- my_params.func = 8; /* set up private parameter block */
- my_params.doc_id = doc_id;
- my_params.slot_id = slot_id;
- my_params.hat_check = hat_check;
- my_params.edition = *edition;
- my_params.fmt_pref[0] = fmt_pref[0];
- my_params.fmt_pref[1] = fmt_pref[1];
- my_params.fmt_pref[2] = fmt_pref[2];
- my_params.ext_data = ext_data;
-
- the_blk.ioCompletion = nil; /* set up driver parameter block */
- the_blk.ioRefNum = iac_ref_num;
- the_blk.ioBuffer = &my_params;
- the_blk.ioReqCount = sizeof(my_params);
- the_blk.ioPosMode = fsFromStart;
- the_blk.ioPosOffset = 0;
- the_err = PBRead(&the_blk.qLink, false); /* read the data */
-
- if (the_err == noErr)
- {
- *edition = my_params.edition;
- *fmt_code = my_params.fmt_code;
- }
-
- return(the_err);
- }
-
-